define(['jquery','lib/knockout','model/viewModel/appViewModel'],function($,ko,appViewModel){
    var app = function(){

        var loadModule =  function(modulePath,moduleId){
           var view = 'text!'+modulePath + '.html',
           controller = modulePath + '.js';
           require([view,controller], function(template,controller){
                    var  scrTag =    '<script type="text/html" id="'+ moduleId +'">' + template +'</script>';
                    $('head').append(scrTag);
                    navigateTo(moduleId);
           });
        },

            navigateTo = function(moduleId){
             appViewModel.activeTemplate(moduleId);
         },

            loadAndNavigate = function(modulePath,moduleId){
                loadModule(modulePath,moduleId);
            },
            init = function(){
                ko.applyBindings(appViewModel);
                var urlHash = window.location.hash;

                 if(urlHash === '#products'){
                     loadAndNavigate('products/productDetails','productDetails');
                 }else{
                     loadAndNavigate('customer/customerDetails','customerDetails')

                 }

            }();


        return {
            loadModule : loadModule,
            navigateTo : navigateTo,
            loadAndNavigate: loadAndNavigate

        }

    }();



    return app;


});
